package org.dromara.business.controller;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.business.domain.bo.CompanyResumeLibraryBo;
import org.dromara.business.domain.vo.CompanyResumeLibraryVo;
import org.dromara.business.service.CompanyResumeLibraryService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公司简历库
 *
 * @author zlj
 * @date 2025-01-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/resumeLibrary")
public class CompanyResumeLibraryController extends BaseController {

    private final CompanyResumeLibraryService companyResumeLibraryService;

    /**
     * 查询公司简历库列表
     */
//    @SaCheckPermission("business:resumeLibrary:list")

    /**
     * 查询我投的简历
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo<CompanyResumeLibraryVo> list(CompanyResumeLibraryBo bo, PageQuery pageQuery) {
        return companyResumeLibraryService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询提交到我公司的简历
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/getResumes")
    public TableDataInfo<CompanyResumeLibraryVo> getResume(CompanyResumeLibraryBo bo, PageQuery pageQuery) {
        return companyResumeLibraryService.getResumes(bo, pageQuery);
    }

    /**
     * 导出公司简历库列表
     */
//    @SaCheckPermission("business:resumeLibrary:export")
    @Log(title = "公司简历库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CompanyResumeLibraryBo bo, HttpServletResponse response) {
        List<CompanyResumeLibraryVo> list = companyResumeLibraryService.queryList(bo);
        ExcelUtil.exportExcel(list, "公司简历库", CompanyResumeLibraryVo.class, response);
    }

    /**
     * 获取公司简历库详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("business:resumeLibrary:query")
    @GetMapping("/{id}")
    public R<CompanyResumeLibraryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(companyResumeLibraryService.queryById(id));
    }

    /**
     * 新增公司简历库
     */
//    @SaCheckPermission("business:resumeLibrary:add")
    @Log(title = "公司简历库", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CompanyResumeLibraryBo bo) {
        return toAjax(companyResumeLibraryService.insertByBo(bo));
    }

    /**
     * 修改公司简历库
     */
//    @SaCheckPermission("business:resumeLibrary:edit")
    @Log(title = "公司简历库", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CompanyResumeLibraryBo bo) {
        return toAjax(companyResumeLibraryService.updateByBo(bo));
    }

    /**
     * 删除公司简历库
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("business:resumeLibrary:remove")
    @Log(title = "公司简历库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(companyResumeLibraryService.deleteWithValidByIds(List.of(ids), true));
    }
}
